package com.corpgovernment.job.batchimport.mapper;

import com.corpgovernment.job.batchimport.entity.db.BatchImportRecordDo;
import com.corpgovernment.job.enums.DeletedEnum;
import com.corpgovernment.organization.common.mybatis.TkMapper;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.apache.ibatis.session.RowBounds;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author ldma
 * @date 2024/1/9
 */
public interface BatchImportRecordMapper extends TkMapper<BatchImportRecordDo> {

    default List<BatchImportRecordDo> pageBatchImportJobRecordDo(List<String> typeList, String fileName, String uid, Integer pageIndex, Integer pageSize) {
        Example example = new Example(BatchImportRecordDo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("deleted", DeletedEnum.FALSE.getCode()).andIn("type", typeList);
        if (StringUtils.isNotBlank(fileName)) {
            criteria.andLike("fileName", "%" + fileName + "%");
        }
        if (StringUtils.isNotBlank(uid)) {
            criteria.andEqualTo("uid", uid);
        }
        example.orderBy("id").desc();
        return selectByExampleAndRowBounds(example, new RowBounds((pageIndex - 1) * pageSize, pageSize));
    }

    default Integer countBatchImportJobRecordDo(List<String> typeList) {
        Example example = new Example(BatchImportRecordDo.class);
        example.createCriteria().andEqualTo("deleted", DeletedEnum.FALSE.getCode()).andIn("type", typeList);
        return selectCountByExample(example);
    }
}
